--******************************************************************
-- Circo.Framework.Generated
-- Fecha:5/16/2009 7:25 PM
--
-- STORED PROCEDURES
--******************************************************************


--******************************************************************
-- Entity: [ActividadEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Actividad_New]
(
 @pIdBoda INT,
 @pIdTipoProd INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Actividad]
(
    [Actividad].[IdBoda],
    [Actividad].[IdTipoProd]
)
   VALUES
(
    @pIdBoda,
    @pIdTipoProd
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Actividad_Update]
(
   @pId INT,
   @pIdBoda INT,
   @pIdTipoProd INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Actividad]
   SET
      [Actividad].[IdBoda] = @pIdBoda,
      [Actividad].[IdTipoProd] = @pIdTipoProd
   WHERE
      [Actividad].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Actividad_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Actividad]
   WHERE
      [Actividad].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Actividad_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Actividad].[Id],
      [Actividad].[IdBoda],
      [Actividad].[IdTipoProd]
   FROM
      [Actividad]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Actividad_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Actividad].[Id],
      [Actividad].[IdBoda],
      [Actividad].[IdTipoProd]
   FROM
      [Actividad]
   WHERE
      [Actividad].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Actividad_FindBy]
   @pId INT = NULL,
   @pIdBoda INT = NULL,
   @pIdTipoProd INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Actividad].[Id],
      [Actividad].[IdBoda],
      [Actividad].[IdTipoProd]
   FROM
      [Actividad]
   WHERE
      (@pId IS NULL OR [Actividad].[Id] = @pId)
       AND
      (@pIdBoda IS NULL OR [Actividad].[IdBoda] = @pIdBoda)
       AND
      (@pIdTipoProd IS NULL OR [Actividad].[IdTipoProd] = @pIdTipoProd)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Actividad_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Actividad_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Actividad_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdBoda_Start INT = NULL,
   @pIdBoda_End INT = NULL,
   @pIdBoda INT = NULL,
   @pIdTipoProd_Start INT = NULL,
   @pIdTipoProd_End INT = NULL,
   @pIdTipoProd INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Actividad].[Id],
      [Actividad].[IdBoda],
      [Actividad].[IdTipoProd]
   FROM
      [Actividad]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Actividad].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Actividad].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Actividad].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Actividad].[Id] = @pId))
 AND
      ((@pIdBoda IS NULL AND 
         ((@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NOT NULL AND [Actividad].[IdBoda] BETWEEN @pIdBoda_Start AND @pIdBoda_End) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NOT NULL AND [Actividad].[IdBoda] <= @pIdBoda_End) OR
          (@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NULL AND [Actividad].[IdBoda] >= @pIdBoda_Start) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NULL))) OR
       (@pIdBoda IS NOT NULL AND [Actividad].[IdBoda] = @pIdBoda))
 AND
      ((@pIdTipoProd IS NULL AND 
         ((@pIdTipoProd_Start IS NOT NULL AND @pIdTipoProd_End IS NOT NULL AND [Actividad].[IdTipoProd] BETWEEN @pIdTipoProd_Start AND @pIdTipoProd_End) OR
          (@pIdTipoProd_Start IS NULL AND @pIdTipoProd_End IS NOT NULL AND [Actividad].[IdTipoProd] <= @pIdTipoProd_End) OR
          (@pIdTipoProd_Start IS NOT NULL AND @pIdTipoProd_End IS NULL AND [Actividad].[IdTipoProd] >= @pIdTipoProd_Start) OR
          (@pIdTipoProd_Start IS NULL AND @pIdTipoProd_End IS NULL))) OR
       (@pIdTipoProd IS NOT NULL AND [Actividad].[IdTipoProd] = @pIdTipoProd))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [BodaEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Boda_New]
(
 @pFecha DATETIME,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Boda]
(
    [Boda].[Fecha]
)
   VALUES
(
    @pFecha
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Boda_Update]
(
   @pId INT,
   @pFecha DATETIME
)
AS
   SET NOCOUNT ON

   UPDATE
      [Boda]
   SET
      [Boda].[Fecha] = @pFecha
   WHERE
      [Boda].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Boda_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Boda]
   WHERE
      [Boda].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Boda_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Boda].[Id],
      [Boda].[Fecha]
   FROM
      [Boda]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Boda_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Boda].[Id],
      [Boda].[Fecha]
   FROM
      [Boda]
   WHERE
      [Boda].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Boda_FindBy]
   @pId INT = NULL,
   @pFecha DATETIME = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Boda].[Id],
      [Boda].[Fecha]
   FROM
      [Boda]
   WHERE
      (@pId IS NULL OR [Boda].[Id] = @pId)
       AND
      (@pFecha IS NULL OR [Boda].[Fecha] = @pFecha)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Boda_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Boda_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Boda_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pFecha_Start DATETIME = NULL,
   @pFecha_End DATETIME = NULL,
   @pFecha DATETIME = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Boda].[Id],
      [Boda].[Fecha]
   FROM
      [Boda]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Boda].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Boda].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Boda].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Boda].[Id] = @pId))
 AND
      ((@pFecha IS NULL AND 
         ((@pFecha_Start IS NOT NULL AND @pFecha_End IS NOT NULL AND [Boda].[Fecha] BETWEEN @pFecha_Start AND @pFecha_End) OR
          (@pFecha_Start IS NULL AND @pFecha_End IS NOT NULL AND [Boda].[Fecha] <= @pFecha_End) OR
          (@pFecha_Start IS NOT NULL AND @pFecha_End IS NULL AND [Boda].[Fecha] >= @pFecha_Start) OR
          (@pFecha_Start IS NULL AND @pFecha_End IS NULL))) OR
       (@pFecha IS NOT NULL AND [Boda].[Fecha] = @pFecha))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [CaracteristicaEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Caracteristica_New]
(
 @pNombre VARCHAR(50),
 @pDetalle VARCHAR(100),
 @pIdProdSer INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Caracteristica]
(
    [Caracteristica].[Nombre],
    [Caracteristica].[Detalle],
    [Caracteristica].[IdProdSer]
)
   VALUES
(
    @pNombre,
    @pDetalle,
    @pIdProdSer
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Caracteristica_Update]
(
   @pId INT,
   @pNombre VARCHAR(50),
   @pDetalle VARCHAR(100),
   @pIdProdSer INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Caracteristica]
   SET
      [Caracteristica].[Nombre] = @pNombre,
      [Caracteristica].[Detalle] = @pDetalle,
      [Caracteristica].[IdProdSer] = @pIdProdSer
   WHERE
      [Caracteristica].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Caracteristica_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Caracteristica]
   WHERE
      [Caracteristica].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Caracteristica_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Caracteristica].[Id],
      [Caracteristica].[Nombre],
      [Caracteristica].[Detalle],
      [Caracteristica].[IdProdSer]
   FROM
      [Caracteristica]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Caracteristica_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Caracteristica].[Id],
      [Caracteristica].[Nombre],
      [Caracteristica].[Detalle],
      [Caracteristica].[IdProdSer]
   FROM
      [Caracteristica]
   WHERE
      [Caracteristica].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Caracteristica_FindBy]
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pDetalle_ExactMatching INT = NULL,
   @pDetalle VARCHAR(100) = NULL,
   @pIdProdSer INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Caracteristica].[Id],
      [Caracteristica].[Nombre],
      [Caracteristica].[Detalle],
      [Caracteristica].[IdProdSer]
   FROM
      [Caracteristica]
   WHERE
      (@pId IS NULL OR [Caracteristica].[Id] = @pId)
       AND
      (@pNombre IS NULL OR [Caracteristica].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pDetalle IS NULL OR [Caracteristica].[Detalle] LIKE (CASE @pDetalle_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDetalle + (CASE @pDetalle_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdProdSer IS NULL OR [Caracteristica].[IdProdSer] = @pIdProdSer)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Caracteristica_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Caracteristica_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Caracteristica_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pDetalle_ExactMatching INT = NULL,
   @pDetalle VARCHAR(100) = NULL,
   @pIdProdSer_Start INT = NULL,
   @pIdProdSer_End INT = NULL,
   @pIdProdSer INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Caracteristica].[Id],
      [Caracteristica].[Nombre],
      [Caracteristica].[Detalle],
      [Caracteristica].[IdProdSer]
   FROM
      [Caracteristica]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Caracteristica].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Caracteristica].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Caracteristica].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Caracteristica].[Id] = @pId))
 AND
      (@pNombre IS NULL OR [Caracteristica].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pDetalle IS NULL OR [Caracteristica].[Detalle] LIKE (CASE @pDetalle_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDetalle + (CASE @pDetalle_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdProdSer IS NULL AND 
         ((@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NOT NULL AND [Caracteristica].[IdProdSer] BETWEEN @pIdProdSer_Start AND @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NOT NULL AND [Caracteristica].[IdProdSer] <= @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NULL AND [Caracteristica].[IdProdSer] >= @pIdProdSer_Start) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NULL))) OR
       (@pIdProdSer IS NOT NULL AND [Caracteristica].[IdProdSer] = @pIdProdSer))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ComentarioEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Comentario_New]
(
 @pIdUsuario INT,
 @pIdProdSer INT,
 @pComentario VARCHAR(500),
 @pCalificacion SMALLINT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Comentario]
(
    [Comentario].[IdUsuario],
    [Comentario].[IdProdSer],
    [Comentario].[Comentario],
    [Comentario].[Calificacion]
)
   VALUES
(
    @pIdUsuario,
    @pIdProdSer,
    @pComentario,
    @pCalificacion
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Comentario_Update]
(
   @pId INT,
   @pIdUsuario INT,
   @pIdProdSer INT,
   @pComentario VARCHAR(500),
   @pCalificacion SMALLINT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Comentario]
   SET
      [Comentario].[IdUsuario] = @pIdUsuario,
      [Comentario].[IdProdSer] = @pIdProdSer,
      [Comentario].[Comentario] = @pComentario,
      [Comentario].[Calificacion] = @pCalificacion
   WHERE
      [Comentario].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Comentario_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Comentario]
   WHERE
      [Comentario].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Comentario_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Comentario].[Id],
      [Comentario].[IdUsuario],
      [Comentario].[IdProdSer],
      [Comentario].[Comentario],
      [Comentario].[Calificacion]
   FROM
      [Comentario]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Comentario_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Comentario].[Id],
      [Comentario].[IdUsuario],
      [Comentario].[IdProdSer],
      [Comentario].[Comentario],
      [Comentario].[Calificacion]
   FROM
      [Comentario]
   WHERE
      [Comentario].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Comentario_FindBy]
   @pId INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdProdSer INT = NULL,
   @pComentario_ExactMatching INT = NULL,
   @pComentario VARCHAR(500) = NULL,
   @pCalificacion SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Comentario].[Id],
      [Comentario].[IdUsuario],
      [Comentario].[IdProdSer],
      [Comentario].[Comentario],
      [Comentario].[Calificacion]
   FROM
      [Comentario]
   WHERE
      (@pId IS NULL OR [Comentario].[Id] = @pId)
       AND
      (@pIdUsuario IS NULL OR [Comentario].[IdUsuario] = @pIdUsuario)
       AND
      (@pIdProdSer IS NULL OR [Comentario].[IdProdSer] = @pIdProdSer)
       AND
      (@pComentario IS NULL OR [Comentario].[Comentario] LIKE (CASE @pComentario_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pComentario + (CASE @pComentario_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pCalificacion IS NULL OR [Comentario].[Calificacion] = @pCalificacion)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Comentario_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Comentario_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Comentario_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdUsuario_Start INT = NULL,
   @pIdUsuario_End INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdProdSer_Start INT = NULL,
   @pIdProdSer_End INT = NULL,
   @pIdProdSer INT = NULL,
   @pComentario_ExactMatching INT = NULL,
   @pComentario VARCHAR(500) = NULL,
   @pCalificacion_Start SMALLINT = NULL,
   @pCalificacion_End SMALLINT = NULL,
   @pCalificacion SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Comentario].[Id],
      [Comentario].[IdUsuario],
      [Comentario].[IdProdSer],
      [Comentario].[Comentario],
      [Comentario].[Calificacion]
   FROM
      [Comentario]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Comentario].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Comentario].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Comentario].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Comentario].[Id] = @pId))
 AND
      ((@pIdUsuario IS NULL AND 
         ((@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NOT NULL AND [Comentario].[IdUsuario] BETWEEN @pIdUsuario_Start AND @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NOT NULL AND [Comentario].[IdUsuario] <= @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NULL AND [Comentario].[IdUsuario] >= @pIdUsuario_Start) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NULL))) OR
       (@pIdUsuario IS NOT NULL AND [Comentario].[IdUsuario] = @pIdUsuario))
 AND
      ((@pIdProdSer IS NULL AND 
         ((@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NOT NULL AND [Comentario].[IdProdSer] BETWEEN @pIdProdSer_Start AND @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NOT NULL AND [Comentario].[IdProdSer] <= @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NULL AND [Comentario].[IdProdSer] >= @pIdProdSer_Start) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NULL))) OR
       (@pIdProdSer IS NOT NULL AND [Comentario].[IdProdSer] = @pIdProdSer))
 AND
      (@pComentario IS NULL OR [Comentario].[Comentario] LIKE (CASE @pComentario_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pComentario + (CASE @pComentario_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pCalificacion IS NULL AND 
         ((@pCalificacion_Start IS NOT NULL AND @pCalificacion_End IS NOT NULL AND [Comentario].[Calificacion] BETWEEN @pCalificacion_Start AND @pCalificacion_End) OR
          (@pCalificacion_Start IS NULL AND @pCalificacion_End IS NOT NULL AND [Comentario].[Calificacion] <= @pCalificacion_End) OR
          (@pCalificacion_Start IS NOT NULL AND @pCalificacion_End IS NULL AND [Comentario].[Calificacion] >= @pCalificacion_Start) OR
          (@pCalificacion_Start IS NULL AND @pCalificacion_End IS NULL))) OR
       (@pCalificacion IS NOT NULL AND [Comentario].[Calificacion] = @pCalificacion))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ConsultaEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Consulta_New]
(
 @pIdUsuario INT,
 @pIdProdser INT,
 @pConsulta VARCHAR(500),
 @pRespuesta VARCHAR(500),
 @pRespondido BIT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Consulta]
(
    [Consulta].[IdUsuario],
    [Consulta].[IdProdser],
    [Consulta].[Consulta],
    [Consulta].[Respuesta],
    [Consulta].[Respondido]
)
   VALUES
(
    @pIdUsuario,
    @pIdProdser,
    @pConsulta,
    @pRespuesta,
    @pRespondido
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Consulta_Update]
(
   @pId INT,
   @pIdUsuario INT,
   @pIdProdser INT,
   @pConsulta VARCHAR(500),
   @pRespuesta VARCHAR(500),
   @pRespondido BIT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Consulta]
   SET
      [Consulta].[IdUsuario] = @pIdUsuario,
      [Consulta].[IdProdser] = @pIdProdser,
      [Consulta].[Consulta] = @pConsulta,
      [Consulta].[Respuesta] = @pRespuesta,
      [Consulta].[Respondido] = @pRespondido
   WHERE
      [Consulta].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Consulta_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Consulta]
   WHERE
      [Consulta].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Consulta_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Consulta].[Id],
      [Consulta].[IdUsuario],
      [Consulta].[IdProdser],
      [Consulta].[Consulta],
      [Consulta].[Respuesta],
      [Consulta].[Respondido]
   FROM
      [Consulta]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Consulta_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Consulta].[Id],
      [Consulta].[IdUsuario],
      [Consulta].[IdProdser],
      [Consulta].[Consulta],
      [Consulta].[Respuesta],
      [Consulta].[Respondido]
   FROM
      [Consulta]
   WHERE
      [Consulta].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Consulta_FindBy]
   @pId INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdProdser INT = NULL,
   @pConsulta_ExactMatching INT = NULL,
   @pConsulta VARCHAR(500) = NULL,
   @pRespuesta_ExactMatching INT = NULL,
   @pRespuesta VARCHAR(500) = NULL,
   @pRespondido BIT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Consulta].[Id],
      [Consulta].[IdUsuario],
      [Consulta].[IdProdser],
      [Consulta].[Consulta],
      [Consulta].[Respuesta],
      [Consulta].[Respondido]
   FROM
      [Consulta]
   WHERE
      (@pId IS NULL OR [Consulta].[Id] = @pId)
       AND
      (@pIdUsuario IS NULL OR [Consulta].[IdUsuario] = @pIdUsuario)
       AND
      (@pIdProdser IS NULL OR [Consulta].[IdProdser] = @pIdProdser)
       AND
      (@pConsulta IS NULL OR [Consulta].[Consulta] LIKE (CASE @pConsulta_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pConsulta + (CASE @pConsulta_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pRespuesta IS NULL OR [Consulta].[Respuesta] LIKE (CASE @pRespuesta_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pRespuesta + (CASE @pRespuesta_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pRespondido IS NULL OR [Consulta].[Respondido] = @pRespondido)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Consulta_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Consulta_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Consulta_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdUsuario_Start INT = NULL,
   @pIdUsuario_End INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdProdser_Start INT = NULL,
   @pIdProdser_End INT = NULL,
   @pIdProdser INT = NULL,
   @pConsulta_ExactMatching INT = NULL,
   @pConsulta VARCHAR(500) = NULL,
   @pRespuesta_ExactMatching INT = NULL,
   @pRespuesta VARCHAR(500) = NULL,
   @pRespondido BIT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Consulta].[Id],
      [Consulta].[IdUsuario],
      [Consulta].[IdProdser],
      [Consulta].[Consulta],
      [Consulta].[Respuesta],
      [Consulta].[Respondido]
   FROM
      [Consulta]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Consulta].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Consulta].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Consulta].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Consulta].[Id] = @pId))
 AND
      ((@pIdUsuario IS NULL AND 
         ((@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NOT NULL AND [Consulta].[IdUsuario] BETWEEN @pIdUsuario_Start AND @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NOT NULL AND [Consulta].[IdUsuario] <= @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NULL AND [Consulta].[IdUsuario] >= @pIdUsuario_Start) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NULL))) OR
       (@pIdUsuario IS NOT NULL AND [Consulta].[IdUsuario] = @pIdUsuario))
 AND
      ((@pIdProdser IS NULL AND 
         ((@pIdProdser_Start IS NOT NULL AND @pIdProdser_End IS NOT NULL AND [Consulta].[IdProdser] BETWEEN @pIdProdser_Start AND @pIdProdser_End) OR
          (@pIdProdser_Start IS NULL AND @pIdProdser_End IS NOT NULL AND [Consulta].[IdProdser] <= @pIdProdser_End) OR
          (@pIdProdser_Start IS NOT NULL AND @pIdProdser_End IS NULL AND [Consulta].[IdProdser] >= @pIdProdser_Start) OR
          (@pIdProdser_Start IS NULL AND @pIdProdser_End IS NULL))) OR
       (@pIdProdser IS NOT NULL AND [Consulta].[IdProdser] = @pIdProdser))
 AND
      (@pConsulta IS NULL OR [Consulta].[Consulta] LIKE (CASE @pConsulta_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pConsulta + (CASE @pConsulta_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pRespuesta IS NULL OR [Consulta].[Respuesta] LIKE (CASE @pRespuesta_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pRespuesta + (CASE @pRespuesta_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pRespondido IS NULL OR [Consulta].[Respondido] = @pRespondido) 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ContactoEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Contacto_New]
(
 @pIdUsuario INT,
 @pIdAmigo INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Contacto]
(
    [Contacto].[IdUsuario],
    [Contacto].[IdAmigo]
)
   VALUES
(
    @pIdUsuario,
    @pIdAmigo
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Contacto_Update]
(
   @pId INT,
   @pIdUsuario INT,
   @pIdAmigo INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Contacto]
   SET
      [Contacto].[IdUsuario] = @pIdUsuario,
      [Contacto].[IdAmigo] = @pIdAmigo
   WHERE
      [Contacto].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contacto_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Contacto]
   WHERE
      [Contacto].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contacto_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Contacto].[Id],
      [Contacto].[IdUsuario],
      [Contacto].[IdAmigo]
   FROM
      [Contacto]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contacto_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Contacto].[Id],
      [Contacto].[IdUsuario],
      [Contacto].[IdAmigo]
   FROM
      [Contacto]
   WHERE
      [Contacto].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contacto_FindBy]
   @pId INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdAmigo INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Contacto].[Id],
      [Contacto].[IdUsuario],
      [Contacto].[IdAmigo]
   FROM
      [Contacto]
   WHERE
      (@pId IS NULL OR [Contacto].[Id] = @pId)
       AND
      (@pIdUsuario IS NULL OR [Contacto].[IdUsuario] = @pIdUsuario)
       AND
      (@pIdAmigo IS NULL OR [Contacto].[IdAmigo] = @pIdAmigo)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contacto_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contacto_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contacto_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdUsuario_Start INT = NULL,
   @pIdUsuario_End INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdAmigo_Start INT = NULL,
   @pIdAmigo_End INT = NULL,
   @pIdAmigo INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Contacto].[Id],
      [Contacto].[IdUsuario],
      [Contacto].[IdAmigo]
   FROM
      [Contacto]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Contacto].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Contacto].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Contacto].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Contacto].[Id] = @pId))
 AND
      ((@pIdUsuario IS NULL AND 
         ((@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NOT NULL AND [Contacto].[IdUsuario] BETWEEN @pIdUsuario_Start AND @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NOT NULL AND [Contacto].[IdUsuario] <= @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NULL AND [Contacto].[IdUsuario] >= @pIdUsuario_Start) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NULL))) OR
       (@pIdUsuario IS NOT NULL AND [Contacto].[IdUsuario] = @pIdUsuario))
 AND
      ((@pIdAmigo IS NULL AND 
         ((@pIdAmigo_Start IS NOT NULL AND @pIdAmigo_End IS NOT NULL AND [Contacto].[IdAmigo] BETWEEN @pIdAmigo_Start AND @pIdAmigo_End) OR
          (@pIdAmigo_Start IS NULL AND @pIdAmigo_End IS NOT NULL AND [Contacto].[IdAmigo] <= @pIdAmigo_End) OR
          (@pIdAmigo_Start IS NOT NULL AND @pIdAmigo_End IS NULL AND [Contacto].[IdAmigo] >= @pIdAmigo_Start) OR
          (@pIdAmigo_Start IS NULL AND @pIdAmigo_End IS NULL))) OR
       (@pIdAmigo IS NOT NULL AND [Contacto].[IdAmigo] = @pIdAmigo))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ContratacionEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Contratacion_New]
(
 @pIdBoda INT,
 @pIdProdSer INT,
 @pPrecio DECIMAL(8,2),
 @pConfirmBoda BIT,
 @pConfirmEmpresa BIT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Contratacion]
(
    [Contratacion].[IdBoda],
    [Contratacion].[IdProdSer],
    [Contratacion].[Precio],
    [Contratacion].[ConfirmBoda],
    [Contratacion].[ConfirmEmpresa]
)
   VALUES
(
    @pIdBoda,
    @pIdProdSer,
    @pPrecio,
    @pConfirmBoda,
    @pConfirmEmpresa
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Contratacion_Update]
(
   @pId INT,
   @pIdBoda INT,
   @pIdProdSer INT,
   @pPrecio DECIMAL(8,2),
   @pConfirmBoda BIT,
   @pConfirmEmpresa BIT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Contratacion]
   SET
      [Contratacion].[IdBoda] = @pIdBoda,
      [Contratacion].[IdProdSer] = @pIdProdSer,
      [Contratacion].[Precio] = @pPrecio,
      [Contratacion].[ConfirmBoda] = @pConfirmBoda,
      [Contratacion].[ConfirmEmpresa] = @pConfirmEmpresa
   WHERE
      [Contratacion].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contratacion_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Contratacion]
   WHERE
      [Contratacion].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contratacion_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Contratacion].[Id],
      [Contratacion].[IdBoda],
      [Contratacion].[IdProdSer],
      [Contratacion].[Precio],
      [Contratacion].[ConfirmBoda],
      [Contratacion].[ConfirmEmpresa]
   FROM
      [Contratacion]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contratacion_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Contratacion].[Id],
      [Contratacion].[IdBoda],
      [Contratacion].[IdProdSer],
      [Contratacion].[Precio],
      [Contratacion].[ConfirmBoda],
      [Contratacion].[ConfirmEmpresa]
   FROM
      [Contratacion]
   WHERE
      [Contratacion].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contratacion_FindBy]
   @pId INT = NULL,
   @pIdBoda INT = NULL,
   @pIdProdSer INT = NULL,
   @pPrecio DECIMAL(8,2) = NULL,
   @pConfirmBoda BIT = NULL,
   @pConfirmEmpresa BIT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Contratacion].[Id],
      [Contratacion].[IdBoda],
      [Contratacion].[IdProdSer],
      [Contratacion].[Precio],
      [Contratacion].[ConfirmBoda],
      [Contratacion].[ConfirmEmpresa]
   FROM
      [Contratacion]
   WHERE
      (@pId IS NULL OR [Contratacion].[Id] = @pId)
       AND
      (@pIdBoda IS NULL OR [Contratacion].[IdBoda] = @pIdBoda)
       AND
      (@pIdProdSer IS NULL OR [Contratacion].[IdProdSer] = @pIdProdSer)
       AND
      (@pPrecio IS NULL OR [Contratacion].[Precio] = @pPrecio)
       AND
      (@pConfirmBoda IS NULL OR [Contratacion].[ConfirmBoda] = @pConfirmBoda)
       AND
      (@pConfirmEmpresa IS NULL OR [Contratacion].[ConfirmEmpresa] = @pConfirmEmpresa)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Contratacion_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Contratacion_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Contratacion_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdBoda_Start INT = NULL,
   @pIdBoda_End INT = NULL,
   @pIdBoda INT = NULL,
   @pIdProdSer_Start INT = NULL,
   @pIdProdSer_End INT = NULL,
   @pIdProdSer INT = NULL,
   @pPrecio_Start DECIMAL(8,2) = NULL,
   @pPrecio_End DECIMAL(8,2) = NULL,
   @pPrecio DECIMAL(8,2) = NULL,
   @pConfirmBoda BIT = NULL,
   @pConfirmEmpresa BIT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Contratacion].[Id],
      [Contratacion].[IdBoda],
      [Contratacion].[IdProdSer],
      [Contratacion].[Precio],
      [Contratacion].[ConfirmBoda],
      [Contratacion].[ConfirmEmpresa]
   FROM
      [Contratacion]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Contratacion].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Contratacion].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Contratacion].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Contratacion].[Id] = @pId))
 AND
      ((@pIdBoda IS NULL AND 
         ((@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NOT NULL AND [Contratacion].[IdBoda] BETWEEN @pIdBoda_Start AND @pIdBoda_End) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NOT NULL AND [Contratacion].[IdBoda] <= @pIdBoda_End) OR
          (@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NULL AND [Contratacion].[IdBoda] >= @pIdBoda_Start) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NULL))) OR
       (@pIdBoda IS NOT NULL AND [Contratacion].[IdBoda] = @pIdBoda))
 AND
      ((@pIdProdSer IS NULL AND 
         ((@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NOT NULL AND [Contratacion].[IdProdSer] BETWEEN @pIdProdSer_Start AND @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NOT NULL AND [Contratacion].[IdProdSer] <= @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NULL AND [Contratacion].[IdProdSer] >= @pIdProdSer_Start) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NULL))) OR
       (@pIdProdSer IS NOT NULL AND [Contratacion].[IdProdSer] = @pIdProdSer))
 AND
      ((@pPrecio IS NULL AND 
         ((@pPrecio_Start IS NOT NULL AND @pPrecio_End IS NOT NULL AND [Contratacion].[Precio] BETWEEN @pPrecio_Start AND @pPrecio_End) OR
          (@pPrecio_Start IS NULL AND @pPrecio_End IS NOT NULL AND [Contratacion].[Precio] <= @pPrecio_End) OR
          (@pPrecio_Start IS NOT NULL AND @pPrecio_End IS NULL AND [Contratacion].[Precio] >= @pPrecio_Start) OR
          (@pPrecio_Start IS NULL AND @pPrecio_End IS NULL))) OR
       (@pPrecio IS NOT NULL AND [Contratacion].[Precio] = @pPrecio))
 AND
      (@pConfirmBoda IS NULL OR [Contratacion].[ConfirmBoda] = @pConfirmBoda) AND
      (@pConfirmEmpresa IS NULL OR [Contratacion].[ConfirmEmpresa] = @pConfirmEmpresa) 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [FotoBodaEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_FotoBoda_New]
(
 @pImagen VARBINARY(MAX),
 @pIdBoda INT,
 @pNombre VARCHAR(100),
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [FotoBoda]
(
    [FotoBoda].[Imagen],
    [FotoBoda].[IdBoda],
    [FotoBoda].[Nombre]
)
   VALUES
(
    @pImagen,
    @pIdBoda,
    @pNombre
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_FotoBoda_Update]
(
   @pId INT,
   @pImagen VARBINARY(MAX),
   @pIdBoda INT,
   @pNombre VARCHAR(100)
)
AS
   SET NOCOUNT ON

   UPDATE
      [FotoBoda]
   SET
      [FotoBoda].[Imagen] = @pImagen,
      [FotoBoda].[IdBoda] = @pIdBoda,
      [FotoBoda].[Nombre] = @pNombre
   WHERE
      [FotoBoda].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_FotoBoda_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [FotoBoda]
   WHERE
      [FotoBoda].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_FotoBoda_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [FotoBoda].[Id],
      [FotoBoda].[Imagen],
      [FotoBoda].[IdBoda],
      [FotoBoda].[Nombre]
   FROM
      [FotoBoda]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_FotoBoda_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [FotoBoda].[Id],
      [FotoBoda].[Imagen],
      [FotoBoda].[IdBoda],
      [FotoBoda].[Nombre]
   FROM
      [FotoBoda]
   WHERE
      [FotoBoda].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_FotoBoda_FindBy]
   @pId INT = NULL,
   @pIdBoda INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(100) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [FotoBoda].[Id],
      [FotoBoda].[Imagen],
      [FotoBoda].[IdBoda],
      [FotoBoda].[Nombre]
   FROM
      [FotoBoda]
   WHERE
      (@pId IS NULL OR [FotoBoda].[Id] = @pId)
       AND
      (@pIdBoda IS NULL OR [FotoBoda].[IdBoda] = @pIdBoda)
       AND
      (@pNombre IS NULL OR [FotoBoda].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_FotoBoda_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_FotoBoda_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_FotoBoda_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdBoda_Start INT = NULL,
   @pIdBoda_End INT = NULL,
   @pIdBoda INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(100) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [FotoBoda].[Id],
      [FotoBoda].[Imagen],
      [FotoBoda].[IdBoda],
      [FotoBoda].[Nombre]
   FROM
      [FotoBoda]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [FotoBoda].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [FotoBoda].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [FotoBoda].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [FotoBoda].[Id] = @pId))
 AND
      ((@pIdBoda IS NULL AND 
         ((@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NOT NULL AND [FotoBoda].[IdBoda] BETWEEN @pIdBoda_Start AND @pIdBoda_End) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NOT NULL AND [FotoBoda].[IdBoda] <= @pIdBoda_End) OR
          (@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NULL AND [FotoBoda].[IdBoda] >= @pIdBoda_Start) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NULL))) OR
       (@pIdBoda IS NOT NULL AND [FotoBoda].[IdBoda] = @pIdBoda))
 AND
      (@pNombre IS NULL OR [FotoBoda].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [FotoEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Foto_New]
(
 @pNombre VARCHAR(50),
 @pDescripcion VARCHAR(250),
 @pIdProdSer INT,
 @pImagen VARBINARY(MAX),
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Foto]
(
    [Foto].[Nombre],
    [Foto].[Descripcion],
    [Foto].[IdProdSer],
    [Foto].[Imagen]
)
   VALUES
(
    @pNombre,
    @pDescripcion,
    @pIdProdSer,
    @pImagen
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Foto_Update]
(
   @pId INT,
   @pNombre VARCHAR(50),
   @pDescripcion VARCHAR(250),
   @pIdProdSer INT,
   @pImagen VARBINARY(MAX)
)
AS
   SET NOCOUNT ON

   UPDATE
      [Foto]
   SET
      [Foto].[Nombre] = @pNombre,
      [Foto].[Descripcion] = @pDescripcion,
      [Foto].[IdProdSer] = @pIdProdSer,
      [Foto].[Imagen] = @pImagen
   WHERE
      [Foto].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Foto_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Foto]
   WHERE
      [Foto].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Foto_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Foto].[Id],
      [Foto].[Nombre],
      [Foto].[Descripcion],
      [Foto].[IdProdSer],
      [Foto].[Imagen]
   FROM
      [Foto]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Foto_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Foto].[Id],
      [Foto].[Nombre],
      [Foto].[Descripcion],
      [Foto].[IdProdSer],
      [Foto].[Imagen]
   FROM
      [Foto]
   WHERE
      [Foto].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Foto_FindBy]
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pDescripcion_ExactMatching INT = NULL,
   @pDescripcion VARCHAR(250) = NULL,
   @pIdProdSer INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Foto].[Id],
      [Foto].[Nombre],
      [Foto].[Descripcion],
      [Foto].[IdProdSer],
      [Foto].[Imagen]
   FROM
      [Foto]
   WHERE
      (@pId IS NULL OR [Foto].[Id] = @pId)
       AND
      (@pNombre IS NULL OR [Foto].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pDescripcion IS NULL OR [Foto].[Descripcion] LIKE (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDescripcion + (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdProdSer IS NULL OR [Foto].[IdProdSer] = @pIdProdSer)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Foto_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Foto_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Foto_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pDescripcion_ExactMatching INT = NULL,
   @pDescripcion VARCHAR(250) = NULL,
   @pIdProdSer_Start INT = NULL,
   @pIdProdSer_End INT = NULL,
   @pIdProdSer INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Foto].[Id],
      [Foto].[Nombre],
      [Foto].[Descripcion],
      [Foto].[IdProdSer],
      [Foto].[Imagen]
   FROM
      [Foto]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Foto].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Foto].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Foto].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Foto].[Id] = @pId))
 AND
      (@pNombre IS NULL OR [Foto].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pDescripcion IS NULL OR [Foto].[Descripcion] LIKE (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDescripcion + (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdProdSer IS NULL AND 
         ((@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NOT NULL AND [Foto].[IdProdSer] BETWEEN @pIdProdSer_Start AND @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NOT NULL AND [Foto].[IdProdSer] <= @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NULL AND [Foto].[IdProdSer] >= @pIdProdSer_Start) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NULL))) OR
       (@pIdProdSer IS NOT NULL AND [Foto].[IdProdSer] = @pIdProdSer))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [InvitadoEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Invitado_New]
(
 @pNombre VARCHAR(50),
 @pMail VARCHAR(100),
 @pIdBoda INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Invitado]
(
    [Invitado].[Nombre],
    [Invitado].[Mail],
    [Invitado].[IdBoda]
)
   VALUES
(
    @pNombre,
    @pMail,
    @pIdBoda
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Invitado_Update]
(
   @pId INT,
   @pNombre VARCHAR(50),
   @pMail VARCHAR(100),
   @pIdBoda INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Invitado]
   SET
      [Invitado].[Nombre] = @pNombre,
      [Invitado].[Mail] = @pMail,
      [Invitado].[IdBoda] = @pIdBoda
   WHERE
      [Invitado].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Invitado_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Invitado]
   WHERE
      [Invitado].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Invitado_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Invitado].[Id],
      [Invitado].[Nombre],
      [Invitado].[Mail],
      [Invitado].[IdBoda]
   FROM
      [Invitado]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Invitado_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Invitado].[Id],
      [Invitado].[Nombre],
      [Invitado].[Mail],
      [Invitado].[IdBoda]
   FROM
      [Invitado]
   WHERE
      [Invitado].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Invitado_FindBy]
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pMail_ExactMatching INT = NULL,
   @pMail VARCHAR(100) = NULL,
   @pIdBoda INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Invitado].[Id],
      [Invitado].[Nombre],
      [Invitado].[Mail],
      [Invitado].[IdBoda]
   FROM
      [Invitado]
   WHERE
      (@pId IS NULL OR [Invitado].[Id] = @pId)
       AND
      (@pNombre IS NULL OR [Invitado].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pMail IS NULL OR [Invitado].[Mail] LIKE (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pMail + (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdBoda IS NULL OR [Invitado].[IdBoda] = @pIdBoda)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Invitado_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Invitado_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Invitado_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pMail_ExactMatching INT = NULL,
   @pMail VARCHAR(100) = NULL,
   @pIdBoda_Start INT = NULL,
   @pIdBoda_End INT = NULL,
   @pIdBoda INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Invitado].[Id],
      [Invitado].[Nombre],
      [Invitado].[Mail],
      [Invitado].[IdBoda]
   FROM
      [Invitado]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Invitado].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Invitado].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Invitado].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Invitado].[Id] = @pId))
 AND
      (@pNombre IS NULL OR [Invitado].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pMail IS NULL OR [Invitado].[Mail] LIKE (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pMail + (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdBoda IS NULL AND 
         ((@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NOT NULL AND [Invitado].[IdBoda] BETWEEN @pIdBoda_Start AND @pIdBoda_End) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NOT NULL AND [Invitado].[IdBoda] <= @pIdBoda_End) OR
          (@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NULL AND [Invitado].[IdBoda] >= @pIdBoda_Start) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NULL))) OR
       (@pIdBoda IS NOT NULL AND [Invitado].[IdBoda] = @pIdBoda))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [LocalidadEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Localidad_New]
(
 @pIdProvincia INT,
 @pNombre VARCHAR(50),
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Localidad]
(
    [Localidad].[IdProvincia],
    [Localidad].[Nombre]
)
   VALUES
(
    @pIdProvincia,
    @pNombre
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Localidad_Update]
(
   @pId INT,
   @pIdProvincia INT,
   @pNombre VARCHAR(50)
)
AS
   SET NOCOUNT ON

   UPDATE
      [Localidad]
   SET
      [Localidad].[IdProvincia] = @pIdProvincia,
      [Localidad].[Nombre] = @pNombre
   WHERE
      [Localidad].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Localidad_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Localidad]
   WHERE
      [Localidad].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Localidad_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Localidad].[Id],
      [Localidad].[IdProvincia],
      [Localidad].[Nombre]
   FROM
      [Localidad]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Localidad_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Localidad].[Id],
      [Localidad].[IdProvincia],
      [Localidad].[Nombre]
   FROM
      [Localidad]
   WHERE
      [Localidad].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Localidad_FindBy]
   @pId INT = NULL,
   @pIdProvincia INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Localidad].[Id],
      [Localidad].[IdProvincia],
      [Localidad].[Nombre]
   FROM
      [Localidad]
   WHERE
      (@pId IS NULL OR [Localidad].[Id] = @pId)
       AND
      (@pIdProvincia IS NULL OR [Localidad].[IdProvincia] = @pIdProvincia)
       AND
      (@pNombre IS NULL OR [Localidad].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Localidad_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Localidad_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Localidad_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdProvincia_Start INT = NULL,
   @pIdProvincia_End INT = NULL,
   @pIdProvincia INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Localidad].[Id],
      [Localidad].[IdProvincia],
      [Localidad].[Nombre]
   FROM
      [Localidad]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Localidad].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Localidad].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Localidad].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Localidad].[Id] = @pId))
 AND
      ((@pIdProvincia IS NULL AND 
         ((@pIdProvincia_Start IS NOT NULL AND @pIdProvincia_End IS NOT NULL AND [Localidad].[IdProvincia] BETWEEN @pIdProvincia_Start AND @pIdProvincia_End) OR
          (@pIdProvincia_Start IS NULL AND @pIdProvincia_End IS NOT NULL AND [Localidad].[IdProvincia] <= @pIdProvincia_End) OR
          (@pIdProvincia_Start IS NOT NULL AND @pIdProvincia_End IS NULL AND [Localidad].[IdProvincia] >= @pIdProvincia_Start) OR
          (@pIdProvincia_Start IS NULL AND @pIdProvincia_End IS NULL))) OR
       (@pIdProvincia IS NOT NULL AND [Localidad].[IdProvincia] = @pIdProvincia))
 AND
      (@pNombre IS NULL OR [Localidad].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ProdSerEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_ProdSer_New]
(
 @pIdTipo INT,
 @pPrecio DECIMAL(10,2),
 @pCategoria SMALLINT,
 @pDescripcion VARCHAR(250),
 @pIdProveedor INT,
 @pDenominacion VARCHAR(100),
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [ProdSer]
(
    [ProdSer].[IdTipo],
    [ProdSer].[Precio],
    [ProdSer].[Categoria],
    [ProdSer].[Descripcion],
    [ProdSer].[IdProveedor],
    [ProdSer].[Denominacion]
)
   VALUES
(
    @pIdTipo,
    @pPrecio,
    @pCategoria,
    @pDescripcion,
    @pIdProveedor,
    @pDenominacion
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_ProdSer_Update]
(
   @pId INT,
   @pIdTipo INT,
   @pPrecio DECIMAL(10,2),
   @pCategoria SMALLINT,
   @pDescripcion VARCHAR(250),
   @pIdProveedor INT,
   @pDenominacion VARCHAR(100)
)
AS
   SET NOCOUNT ON

   UPDATE
      [ProdSer]
   SET
      [ProdSer].[IdTipo] = @pIdTipo,
      [ProdSer].[Precio] = @pPrecio,
      [ProdSer].[Categoria] = @pCategoria,
      [ProdSer].[Descripcion] = @pDescripcion,
      [ProdSer].[IdProveedor] = @pIdProveedor,
      [ProdSer].[Denominacion] = @pDenominacion
   WHERE
      [ProdSer].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSer_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [ProdSer]
   WHERE
      [ProdSer].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSer_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [ProdSer].[Id],
      [ProdSer].[IdTipo],
      [ProdSer].[Precio],
      [ProdSer].[Categoria],
      [ProdSer].[Descripcion],
      [ProdSer].[IdProveedor],
      [ProdSer].[Denominacion]
   FROM
      [ProdSer]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSer_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [ProdSer].[Id],
      [ProdSer].[IdTipo],
      [ProdSer].[Precio],
      [ProdSer].[Categoria],
      [ProdSer].[Descripcion],
      [ProdSer].[IdProveedor],
      [ProdSer].[Denominacion]
   FROM
      [ProdSer]
   WHERE
      [ProdSer].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSer_FindBy]
   @pId INT = NULL,
   @pIdTipo INT = NULL,
   @pPrecio DECIMAL(10,2) = NULL,
   @pCategoria SMALLINT = NULL,
   @pDescripcion_ExactMatching INT = NULL,
   @pDescripcion VARCHAR(250) = NULL,
   @pIdProveedor INT = NULL,
   @pDenominacion_ExactMatching INT = NULL,
   @pDenominacion VARCHAR(100) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [ProdSer].[Id],
      [ProdSer].[IdTipo],
      [ProdSer].[Precio],
      [ProdSer].[Categoria],
      [ProdSer].[Descripcion],
      [ProdSer].[IdProveedor],
      [ProdSer].[Denominacion]
   FROM
      [ProdSer]
   WHERE
      (@pId IS NULL OR [ProdSer].[Id] = @pId)
       AND
      (@pIdTipo IS NULL OR [ProdSer].[IdTipo] = @pIdTipo)
       AND
      (@pPrecio IS NULL OR [ProdSer].[Precio] = @pPrecio)
       AND
      (@pCategoria IS NULL OR [ProdSer].[Categoria] = @pCategoria)
       AND
      (@pDescripcion IS NULL OR [ProdSer].[Descripcion] LIKE (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDescripcion + (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdProveedor IS NULL OR [ProdSer].[IdProveedor] = @pIdProveedor)
       AND
      (@pDenominacion IS NULL OR [ProdSer].[Denominacion] LIKE (CASE @pDenominacion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDenominacion + (CASE @pDenominacion_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSer_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSer_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSer_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdTipo_Start INT = NULL,
   @pIdTipo_End INT = NULL,
   @pIdTipo INT = NULL,
   @pPrecio_Start DECIMAL(10,2) = NULL,
   @pPrecio_End DECIMAL(10,2) = NULL,
   @pPrecio DECIMAL(10,2) = NULL,
   @pCategoria_Start SMALLINT = NULL,
   @pCategoria_End SMALLINT = NULL,
   @pCategoria SMALLINT = NULL,
   @pDescripcion_ExactMatching INT = NULL,
   @pDescripcion VARCHAR(250) = NULL,
   @pIdProveedor_Start INT = NULL,
   @pIdProveedor_End INT = NULL,
   @pIdProveedor INT = NULL,
   @pDenominacion_ExactMatching INT = NULL,
   @pDenominacion VARCHAR(100) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [ProdSer].[Id],
      [ProdSer].[IdTipo],
      [ProdSer].[Precio],
      [ProdSer].[Categoria],
      [ProdSer].[Descripcion],
      [ProdSer].[IdProveedor],
      [ProdSer].[Denominacion]
   FROM
      [ProdSer]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [ProdSer].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [ProdSer].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [ProdSer].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [ProdSer].[Id] = @pId))
 AND
      ((@pIdTipo IS NULL AND 
         ((@pIdTipo_Start IS NOT NULL AND @pIdTipo_End IS NOT NULL AND [ProdSer].[IdTipo] BETWEEN @pIdTipo_Start AND @pIdTipo_End) OR
          (@pIdTipo_Start IS NULL AND @pIdTipo_End IS NOT NULL AND [ProdSer].[IdTipo] <= @pIdTipo_End) OR
          (@pIdTipo_Start IS NOT NULL AND @pIdTipo_End IS NULL AND [ProdSer].[IdTipo] >= @pIdTipo_Start) OR
          (@pIdTipo_Start IS NULL AND @pIdTipo_End IS NULL))) OR
       (@pIdTipo IS NOT NULL AND [ProdSer].[IdTipo] = @pIdTipo))
 AND
      ((@pPrecio IS NULL AND 
         ((@pPrecio_Start IS NOT NULL AND @pPrecio_End IS NOT NULL AND [ProdSer].[Precio] BETWEEN @pPrecio_Start AND @pPrecio_End) OR
          (@pPrecio_Start IS NULL AND @pPrecio_End IS NOT NULL AND [ProdSer].[Precio] <= @pPrecio_End) OR
          (@pPrecio_Start IS NOT NULL AND @pPrecio_End IS NULL AND [ProdSer].[Precio] >= @pPrecio_Start) OR
          (@pPrecio_Start IS NULL AND @pPrecio_End IS NULL))) OR
       (@pPrecio IS NOT NULL AND [ProdSer].[Precio] = @pPrecio))
 AND
      ((@pCategoria IS NULL AND 
         ((@pCategoria_Start IS NOT NULL AND @pCategoria_End IS NOT NULL AND [ProdSer].[Categoria] BETWEEN @pCategoria_Start AND @pCategoria_End) OR
          (@pCategoria_Start IS NULL AND @pCategoria_End IS NOT NULL AND [ProdSer].[Categoria] <= @pCategoria_End) OR
          (@pCategoria_Start IS NOT NULL AND @pCategoria_End IS NULL AND [ProdSer].[Categoria] >= @pCategoria_Start) OR
          (@pCategoria_Start IS NULL AND @pCategoria_End IS NULL))) OR
       (@pCategoria IS NOT NULL AND [ProdSer].[Categoria] = @pCategoria))
 AND
      (@pDescripcion IS NULL OR [ProdSer].[Descripcion] LIKE (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDescripcion + (CASE @pDescripcion_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdProveedor IS NULL AND 
         ((@pIdProveedor_Start IS NOT NULL AND @pIdProveedor_End IS NOT NULL AND [ProdSer].[IdProveedor] BETWEEN @pIdProveedor_Start AND @pIdProveedor_End) OR
          (@pIdProveedor_Start IS NULL AND @pIdProveedor_End IS NOT NULL AND [ProdSer].[IdProveedor] <= @pIdProveedor_End) OR
          (@pIdProveedor_Start IS NOT NULL AND @pIdProveedor_End IS NULL AND [ProdSer].[IdProveedor] >= @pIdProveedor_Start) OR
          (@pIdProveedor_Start IS NULL AND @pIdProveedor_End IS NULL))) OR
       (@pIdProveedor IS NOT NULL AND [ProdSer].[IdProveedor] = @pIdProveedor))
 AND
      (@pDenominacion IS NULL OR [ProdSer].[Denominacion] LIKE (CASE @pDenominacion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDenominacion + (CASE @pDenominacion_ExactMatching WHEN 1 THEN '' ELSE '%' END)) 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ProdSerLocEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_ProdSerLoc_New]
(
 @pIdProdSer INT,
 @pIdLocalidad INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [ProdSerLoc]
(
    [ProdSerLoc].[IdProdSer],
    [ProdSerLoc].[IdLocalidad]
)
   VALUES
(
    @pIdProdSer,
    @pIdLocalidad
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_ProdSerLoc_Update]
(
   @pId INT,
   @pIdProdSer INT,
   @pIdLocalidad INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [ProdSerLoc]
   SET
      [ProdSerLoc].[IdProdSer] = @pIdProdSer,
      [ProdSerLoc].[IdLocalidad] = @pIdLocalidad
   WHERE
      [ProdSerLoc].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSerLoc_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [ProdSerLoc]
   WHERE
      [ProdSerLoc].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSerLoc_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [ProdSerLoc].[Id],
      [ProdSerLoc].[IdProdSer],
      [ProdSerLoc].[IdLocalidad]
   FROM
      [ProdSerLoc]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSerLoc_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [ProdSerLoc].[Id],
      [ProdSerLoc].[IdProdSer],
      [ProdSerLoc].[IdLocalidad]
   FROM
      [ProdSerLoc]
   WHERE
      [ProdSerLoc].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSerLoc_FindBy]
   @pId INT = NULL,
   @pIdProdSer INT = NULL,
   @pIdLocalidad INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [ProdSerLoc].[Id],
      [ProdSerLoc].[IdProdSer],
      [ProdSerLoc].[IdLocalidad]
   FROM
      [ProdSerLoc]
   WHERE
      (@pId IS NULL OR [ProdSerLoc].[Id] = @pId)
       AND
      (@pIdProdSer IS NULL OR [ProdSerLoc].[IdProdSer] = @pIdProdSer)
       AND
      (@pIdLocalidad IS NULL OR [ProdSerLoc].[IdLocalidad] = @pIdLocalidad)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_ProdSerLoc_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_ProdSerLoc_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_ProdSerLoc_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdProdSer_Start INT = NULL,
   @pIdProdSer_End INT = NULL,
   @pIdProdSer INT = NULL,
   @pIdLocalidad_Start INT = NULL,
   @pIdLocalidad_End INT = NULL,
   @pIdLocalidad INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [ProdSerLoc].[Id],
      [ProdSerLoc].[IdProdSer],
      [ProdSerLoc].[IdLocalidad]
   FROM
      [ProdSerLoc]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [ProdSerLoc].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [ProdSerLoc].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [ProdSerLoc].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [ProdSerLoc].[Id] = @pId))
 AND
      ((@pIdProdSer IS NULL AND 
         ((@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NOT NULL AND [ProdSerLoc].[IdProdSer] BETWEEN @pIdProdSer_Start AND @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NOT NULL AND [ProdSerLoc].[IdProdSer] <= @pIdProdSer_End) OR
          (@pIdProdSer_Start IS NOT NULL AND @pIdProdSer_End IS NULL AND [ProdSerLoc].[IdProdSer] >= @pIdProdSer_Start) OR
          (@pIdProdSer_Start IS NULL AND @pIdProdSer_End IS NULL))) OR
       (@pIdProdSer IS NOT NULL AND [ProdSerLoc].[IdProdSer] = @pIdProdSer))
 AND
      ((@pIdLocalidad IS NULL AND 
         ((@pIdLocalidad_Start IS NOT NULL AND @pIdLocalidad_End IS NOT NULL AND [ProdSerLoc].[IdLocalidad] BETWEEN @pIdLocalidad_Start AND @pIdLocalidad_End) OR
          (@pIdLocalidad_Start IS NULL AND @pIdLocalidad_End IS NOT NULL AND [ProdSerLoc].[IdLocalidad] <= @pIdLocalidad_End) OR
          (@pIdLocalidad_Start IS NOT NULL AND @pIdLocalidad_End IS NULL AND [ProdSerLoc].[IdLocalidad] >= @pIdLocalidad_Start) OR
          (@pIdLocalidad_Start IS NULL AND @pIdLocalidad_End IS NULL))) OR
       (@pIdLocalidad IS NOT NULL AND [ProdSerLoc].[IdLocalidad] = @pIdLocalidad))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ProveedorEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Proveedor_New]
(
 @pNombre VARCHAR(50),
 @pIdProvincia INT,
 @pDireccion VARCHAR(250),
 @pIdLocalidad INT,
 @pTelefono VARCHAR(50),
 @pMail VARCHAR(100),
 @pNombreUsuario VARCHAR(50),
 @pContrasenia VARCHAR(50),
 @pNombreResp VARCHAR(50),
 @pApellidoResp VARCHAR(50),
 @pDNIResp VARCHAR(15),
 @pActivo BIT,
 @pTipoDNI SMALLINT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Proveedor]
(
    [Proveedor].[Nombre],
    [Proveedor].[IdProvincia],
    [Proveedor].[Direccion],
    [Proveedor].[IdLocalidad],
    [Proveedor].[Telefono],
    [Proveedor].[Mail],
    [Proveedor].[NombreUsuario],
    [Proveedor].[Contrasenia],
    [Proveedor].[NombreResp],
    [Proveedor].[ApellidoResp],
    [Proveedor].[DNIResp],
    [Proveedor].[Activo],
    [Proveedor].[TipoDNI]
)
   VALUES
(
    @pNombre,
    @pIdProvincia,
    @pDireccion,
    @pIdLocalidad,
    @pTelefono,
    @pMail,
    @pNombreUsuario,
    @pContrasenia,
    @pNombreResp,
    @pApellidoResp,
    @pDNIResp,
    @pActivo,
    @pTipoDNI
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Proveedor_Update]
(
   @pId INT,
   @pNombre VARCHAR(50),
   @pIdProvincia INT,
   @pDireccion VARCHAR(250),
   @pIdLocalidad INT,
   @pTelefono VARCHAR(50),
   @pMail VARCHAR(100),
   @pNombreUsuario VARCHAR(50),
   @pContrasenia VARCHAR(50),
   @pNombreResp VARCHAR(50),
   @pApellidoResp VARCHAR(50),
   @pDNIResp VARCHAR(15),
   @pActivo BIT,
   @pTipoDNI SMALLINT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Proveedor]
   SET
      [Proveedor].[Nombre] = @pNombre,
      [Proveedor].[IdProvincia] = @pIdProvincia,
      [Proveedor].[Direccion] = @pDireccion,
      [Proveedor].[IdLocalidad] = @pIdLocalidad,
      [Proveedor].[Telefono] = @pTelefono,
      [Proveedor].[Mail] = @pMail,
      [Proveedor].[NombreUsuario] = @pNombreUsuario,
      [Proveedor].[Contrasenia] = @pContrasenia,
      [Proveedor].[NombreResp] = @pNombreResp,
      [Proveedor].[ApellidoResp] = @pApellidoResp,
      [Proveedor].[DNIResp] = @pDNIResp,
      [Proveedor].[Activo] = @pActivo,
      [Proveedor].[TipoDNI] = @pTipoDNI
   WHERE
      [Proveedor].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Proveedor_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Proveedor]
   WHERE
      [Proveedor].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Proveedor_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Proveedor].[Id],
      [Proveedor].[Nombre],
      [Proveedor].[IdProvincia],
      [Proveedor].[Direccion],
      [Proveedor].[IdLocalidad],
      [Proveedor].[Telefono],
      [Proveedor].[Mail],
      [Proveedor].[NombreUsuario],
      [Proveedor].[Contrasenia],
      [Proveedor].[NombreResp],
      [Proveedor].[ApellidoResp],
      [Proveedor].[DNIResp],
      [Proveedor].[Activo],
      [Proveedor].[TipoDNI]
   FROM
      [Proveedor]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Proveedor_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Proveedor].[Id],
      [Proveedor].[Nombre],
      [Proveedor].[IdProvincia],
      [Proveedor].[Direccion],
      [Proveedor].[IdLocalidad],
      [Proveedor].[Telefono],
      [Proveedor].[Mail],
      [Proveedor].[NombreUsuario],
      [Proveedor].[Contrasenia],
      [Proveedor].[NombreResp],
      [Proveedor].[ApellidoResp],
      [Proveedor].[DNIResp],
      [Proveedor].[Activo],
      [Proveedor].[TipoDNI]
   FROM
      [Proveedor]
   WHERE
      [Proveedor].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Proveedor_FindBy]
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pIdProvincia INT = NULL,
   @pDireccion_ExactMatching INT = NULL,
   @pDireccion VARCHAR(250) = NULL,
   @pIdLocalidad INT = NULL,
   @pTelefono_ExactMatching INT = NULL,
   @pTelefono VARCHAR(50) = NULL,
   @pMail_ExactMatching INT = NULL,
   @pMail VARCHAR(100) = NULL,
   @pNombreUsuario_ExactMatching INT = NULL,
   @pNombreUsuario VARCHAR(50) = NULL,
   @pContrasenia_ExactMatching INT = NULL,
   @pContrasenia VARCHAR(50) = NULL,
   @pNombreResp_ExactMatching INT = NULL,
   @pNombreResp VARCHAR(50) = NULL,
   @pApellidoResp_ExactMatching INT = NULL,
   @pApellidoResp VARCHAR(50) = NULL,
   @pDNIResp_ExactMatching INT = NULL,
   @pDNIResp VARCHAR(15) = NULL,
   @pActivo BIT = NULL,
   @pTipoDNI SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Proveedor].[Id],
      [Proveedor].[Nombre],
      [Proveedor].[IdProvincia],
      [Proveedor].[Direccion],
      [Proveedor].[IdLocalidad],
      [Proveedor].[Telefono],
      [Proveedor].[Mail],
      [Proveedor].[NombreUsuario],
      [Proveedor].[Contrasenia],
      [Proveedor].[NombreResp],
      [Proveedor].[ApellidoResp],
      [Proveedor].[DNIResp],
      [Proveedor].[Activo],
      [Proveedor].[TipoDNI]
   FROM
      [Proveedor]
   WHERE
      (@pId IS NULL OR [Proveedor].[Id] = @pId)
       AND
      (@pNombre IS NULL OR [Proveedor].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdProvincia IS NULL OR [Proveedor].[IdProvincia] = @pIdProvincia)
       AND
      (@pDireccion IS NULL OR [Proveedor].[Direccion] LIKE (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDireccion + (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdLocalidad IS NULL OR [Proveedor].[IdLocalidad] = @pIdLocalidad)
       AND
      (@pTelefono IS NULL OR [Proveedor].[Telefono] LIKE (CASE @pTelefono_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pTelefono + (CASE @pTelefono_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pMail IS NULL OR [Proveedor].[Mail] LIKE (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pMail + (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pNombreUsuario IS NULL OR [Proveedor].[NombreUsuario] LIKE (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombreUsuario + (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pContrasenia IS NULL OR [Proveedor].[Contrasenia] LIKE (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pContrasenia + (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pNombreResp IS NULL OR [Proveedor].[NombreResp] LIKE (CASE @pNombreResp_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombreResp + (CASE @pNombreResp_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pApellidoResp IS NULL OR [Proveedor].[ApellidoResp] LIKE (CASE @pApellidoResp_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pApellidoResp + (CASE @pApellidoResp_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pDNIResp IS NULL OR [Proveedor].[DNIResp] LIKE (CASE @pDNIResp_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDNIResp + (CASE @pDNIResp_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pActivo IS NULL OR [Proveedor].[Activo] = @pActivo)
       AND
      (@pTipoDNI IS NULL OR [Proveedor].[TipoDNI] = @pTipoDNI)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Proveedor_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Proveedor_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Proveedor_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pIdProvincia_Start INT = NULL,
   @pIdProvincia_End INT = NULL,
   @pIdProvincia INT = NULL,
   @pDireccion_ExactMatching INT = NULL,
   @pDireccion VARCHAR(250) = NULL,
   @pIdLocalidad_Start INT = NULL,
   @pIdLocalidad_End INT = NULL,
   @pIdLocalidad INT = NULL,
   @pTelefono_ExactMatching INT = NULL,
   @pTelefono VARCHAR(50) = NULL,
   @pMail_ExactMatching INT = NULL,
   @pMail VARCHAR(100) = NULL,
   @pNombreUsuario_ExactMatching INT = NULL,
   @pNombreUsuario VARCHAR(50) = NULL,
   @pContrasenia_ExactMatching INT = NULL,
   @pContrasenia VARCHAR(50) = NULL,
   @pNombreResp_ExactMatching INT = NULL,
   @pNombreResp VARCHAR(50) = NULL,
   @pApellidoResp_ExactMatching INT = NULL,
   @pApellidoResp VARCHAR(50) = NULL,
   @pDNIResp_ExactMatching INT = NULL,
   @pDNIResp VARCHAR(15) = NULL,
   @pActivo BIT = NULL,
   @pTipoDNI_Start SMALLINT = NULL,
   @pTipoDNI_End SMALLINT = NULL,
   @pTipoDNI SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Proveedor].[Id],
      [Proveedor].[Nombre],
      [Proveedor].[IdProvincia],
      [Proveedor].[Direccion],
      [Proveedor].[IdLocalidad],
      [Proveedor].[Telefono],
      [Proveedor].[Mail],
      [Proveedor].[NombreUsuario],
      [Proveedor].[Contrasenia],
      [Proveedor].[NombreResp],
      [Proveedor].[ApellidoResp],
      [Proveedor].[DNIResp],
      [Proveedor].[Activo],
      [Proveedor].[TipoDNI]
   FROM
      [Proveedor]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Proveedor].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Proveedor].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Proveedor].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Proveedor].[Id] = @pId))
 AND
      (@pNombre IS NULL OR [Proveedor].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdProvincia IS NULL AND 
         ((@pIdProvincia_Start IS NOT NULL AND @pIdProvincia_End IS NOT NULL AND [Proveedor].[IdProvincia] BETWEEN @pIdProvincia_Start AND @pIdProvincia_End) OR
          (@pIdProvincia_Start IS NULL AND @pIdProvincia_End IS NOT NULL AND [Proveedor].[IdProvincia] <= @pIdProvincia_End) OR
          (@pIdProvincia_Start IS NOT NULL AND @pIdProvincia_End IS NULL AND [Proveedor].[IdProvincia] >= @pIdProvincia_Start) OR
          (@pIdProvincia_Start IS NULL AND @pIdProvincia_End IS NULL))) OR
       (@pIdProvincia IS NOT NULL AND [Proveedor].[IdProvincia] = @pIdProvincia))
 AND
      (@pDireccion IS NULL OR [Proveedor].[Direccion] LIKE (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDireccion + (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdLocalidad IS NULL AND 
         ((@pIdLocalidad_Start IS NOT NULL AND @pIdLocalidad_End IS NOT NULL AND [Proveedor].[IdLocalidad] BETWEEN @pIdLocalidad_Start AND @pIdLocalidad_End) OR
          (@pIdLocalidad_Start IS NULL AND @pIdLocalidad_End IS NOT NULL AND [Proveedor].[IdLocalidad] <= @pIdLocalidad_End) OR
          (@pIdLocalidad_Start IS NOT NULL AND @pIdLocalidad_End IS NULL AND [Proveedor].[IdLocalidad] >= @pIdLocalidad_Start) OR
          (@pIdLocalidad_Start IS NULL AND @pIdLocalidad_End IS NULL))) OR
       (@pIdLocalidad IS NOT NULL AND [Proveedor].[IdLocalidad] = @pIdLocalidad))
 AND
      (@pTelefono IS NULL OR [Proveedor].[Telefono] LIKE (CASE @pTelefono_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pTelefono + (CASE @pTelefono_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pMail IS NULL OR [Proveedor].[Mail] LIKE (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pMail + (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pNombreUsuario IS NULL OR [Proveedor].[NombreUsuario] LIKE (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombreUsuario + (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pContrasenia IS NULL OR [Proveedor].[Contrasenia] LIKE (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pContrasenia + (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pNombreResp IS NULL OR [Proveedor].[NombreResp] LIKE (CASE @pNombreResp_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombreResp + (CASE @pNombreResp_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pApellidoResp IS NULL OR [Proveedor].[ApellidoResp] LIKE (CASE @pApellidoResp_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pApellidoResp + (CASE @pApellidoResp_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pDNIResp IS NULL OR [Proveedor].[DNIResp] LIKE (CASE @pDNIResp_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDNIResp + (CASE @pDNIResp_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pActivo IS NULL OR [Proveedor].[Activo] = @pActivo) AND
      ((@pTipoDNI IS NULL AND 
         ((@pTipoDNI_Start IS NOT NULL AND @pTipoDNI_End IS NOT NULL AND [Proveedor].[TipoDNI] BETWEEN @pTipoDNI_Start AND @pTipoDNI_End) OR
          (@pTipoDNI_Start IS NULL AND @pTipoDNI_End IS NOT NULL AND [Proveedor].[TipoDNI] <= @pTipoDNI_End) OR
          (@pTipoDNI_Start IS NOT NULL AND @pTipoDNI_End IS NULL AND [Proveedor].[TipoDNI] >= @pTipoDNI_Start) OR
          (@pTipoDNI_Start IS NULL AND @pTipoDNI_End IS NULL))) OR
       (@pTipoDNI IS NOT NULL AND [Proveedor].[TipoDNI] = @pTipoDNI))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [ProvinciaEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Provincia_New]
(
 @pNombre VARCHAR(50),
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Provincia]
(
    [Provincia].[Nombre]
)
   VALUES
(
    @pNombre
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Provincia_Update]
(
   @pId INT,
   @pNombre VARCHAR(50)
)
AS
   SET NOCOUNT ON

   UPDATE
      [Provincia]
   SET
      [Provincia].[Nombre] = @pNombre
   WHERE
      [Provincia].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Provincia_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Provincia]
   WHERE
      [Provincia].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Provincia_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Provincia].[Id],
      [Provincia].[Nombre]
   FROM
      [Provincia]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Provincia_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Provincia].[Id],
      [Provincia].[Nombre]
   FROM
      [Provincia]
   WHERE
      [Provincia].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Provincia_FindBy]
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Provincia].[Id],
      [Provincia].[Nombre]
   FROM
      [Provincia]
   WHERE
      (@pId IS NULL OR [Provincia].[Id] = @pId)
       AND
      (@pNombre IS NULL OR [Provincia].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Provincia_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Provincia_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Provincia_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Provincia].[Id],
      [Provincia].[Nombre]
   FROM
      [Provincia]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Provincia].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Provincia].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Provincia].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Provincia].[Id] = @pId))
 AND
      (@pNombre IS NULL OR [Provincia].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [SolicitudDeTipoEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_New]
(
 @pNombrePropuesto VARCHAR(50),
 @pRazon VARCHAR(250),
 @pCategPropuesta SMALLINT,
 @pIdProveedor INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [SolicitudDeTipo]
(
    [SolicitudDeTipo].[NombrePropuesto],
    [SolicitudDeTipo].[Razon],
    [SolicitudDeTipo].[CategPropuesta],
    [SolicitudDeTipo].[IdProveedor]
)
   VALUES
(
    @pNombrePropuesto,
    @pRazon,
    @pCategPropuesta,
    @pIdProveedor
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_Update]
(
   @pId INT,
   @pNombrePropuesto VARCHAR(50),
   @pRazon VARCHAR(250),
   @pCategPropuesta SMALLINT,
   @pIdProveedor INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [SolicitudDeTipo]
   SET
      [SolicitudDeTipo].[NombrePropuesto] = @pNombrePropuesto,
      [SolicitudDeTipo].[Razon] = @pRazon,
      [SolicitudDeTipo].[CategPropuesta] = @pCategPropuesta,
      [SolicitudDeTipo].[IdProveedor] = @pIdProveedor
   WHERE
      [SolicitudDeTipo].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [SolicitudDeTipo]
   WHERE
      [SolicitudDeTipo].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [SolicitudDeTipo].[Id],
      [SolicitudDeTipo].[NombrePropuesto],
      [SolicitudDeTipo].[Razon],
      [SolicitudDeTipo].[CategPropuesta],
      [SolicitudDeTipo].[IdProveedor]
   FROM
      [SolicitudDeTipo]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [SolicitudDeTipo].[Id],
      [SolicitudDeTipo].[NombrePropuesto],
      [SolicitudDeTipo].[Razon],
      [SolicitudDeTipo].[CategPropuesta],
      [SolicitudDeTipo].[IdProveedor]
   FROM
      [SolicitudDeTipo]
   WHERE
      [SolicitudDeTipo].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_FindBy]
   @pId INT = NULL,
   @pNombrePropuesto_ExactMatching INT = NULL,
   @pNombrePropuesto VARCHAR(50) = NULL,
   @pRazon_ExactMatching INT = NULL,
   @pRazon VARCHAR(250) = NULL,
   @pCategPropuesta SMALLINT = NULL,
   @pIdProveedor INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [SolicitudDeTipo].[Id],
      [SolicitudDeTipo].[NombrePropuesto],
      [SolicitudDeTipo].[Razon],
      [SolicitudDeTipo].[CategPropuesta],
      [SolicitudDeTipo].[IdProveedor]
   FROM
      [SolicitudDeTipo]
   WHERE
      (@pId IS NULL OR [SolicitudDeTipo].[Id] = @pId)
       AND
      (@pNombrePropuesto IS NULL OR [SolicitudDeTipo].[NombrePropuesto] LIKE (CASE @pNombrePropuesto_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombrePropuesto + (CASE @pNombrePropuesto_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pRazon IS NULL OR [SolicitudDeTipo].[Razon] LIKE (CASE @pRazon_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pRazon + (CASE @pRazon_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pCategPropuesta IS NULL OR [SolicitudDeTipo].[CategPropuesta] = @pCategPropuesta)
       AND
      (@pIdProveedor IS NULL OR [SolicitudDeTipo].[IdProveedor] = @pIdProveedor)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_SolicitudDeTipo_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_SolicitudDeTipo_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_SolicitudDeTipo_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombrePropuesto_ExactMatching INT = NULL,
   @pNombrePropuesto VARCHAR(50) = NULL,
   @pRazon_ExactMatching INT = NULL,
   @pRazon VARCHAR(250) = NULL,
   @pCategPropuesta_Start SMALLINT = NULL,
   @pCategPropuesta_End SMALLINT = NULL,
   @pCategPropuesta SMALLINT = NULL,
   @pIdProveedor_Start INT = NULL,
   @pIdProveedor_End INT = NULL,
   @pIdProveedor INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [SolicitudDeTipo].[Id],
      [SolicitudDeTipo].[NombrePropuesto],
      [SolicitudDeTipo].[Razon],
      [SolicitudDeTipo].[CategPropuesta],
      [SolicitudDeTipo].[IdProveedor]
   FROM
      [SolicitudDeTipo]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [SolicitudDeTipo].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [SolicitudDeTipo].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [SolicitudDeTipo].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [SolicitudDeTipo].[Id] = @pId))
 AND
      (@pNombrePropuesto IS NULL OR [SolicitudDeTipo].[NombrePropuesto] LIKE (CASE @pNombrePropuesto_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombrePropuesto + (CASE @pNombrePropuesto_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pRazon IS NULL OR [SolicitudDeTipo].[Razon] LIKE (CASE @pRazon_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pRazon + (CASE @pRazon_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pCategPropuesta IS NULL AND 
         ((@pCategPropuesta_Start IS NOT NULL AND @pCategPropuesta_End IS NOT NULL AND [SolicitudDeTipo].[CategPropuesta] BETWEEN @pCategPropuesta_Start AND @pCategPropuesta_End) OR
          (@pCategPropuesta_Start IS NULL AND @pCategPropuesta_End IS NOT NULL AND [SolicitudDeTipo].[CategPropuesta] <= @pCategPropuesta_End) OR
          (@pCategPropuesta_Start IS NOT NULL AND @pCategPropuesta_End IS NULL AND [SolicitudDeTipo].[CategPropuesta] >= @pCategPropuesta_Start) OR
          (@pCategPropuesta_Start IS NULL AND @pCategPropuesta_End IS NULL))) OR
       (@pCategPropuesta IS NOT NULL AND [SolicitudDeTipo].[CategPropuesta] = @pCategPropuesta))
 AND
      ((@pIdProveedor IS NULL AND 
         ((@pIdProveedor_Start IS NOT NULL AND @pIdProveedor_End IS NOT NULL AND [SolicitudDeTipo].[IdProveedor] BETWEEN @pIdProveedor_Start AND @pIdProveedor_End) OR
          (@pIdProveedor_Start IS NULL AND @pIdProveedor_End IS NOT NULL AND [SolicitudDeTipo].[IdProveedor] <= @pIdProveedor_End) OR
          (@pIdProveedor_Start IS NOT NULL AND @pIdProveedor_End IS NULL AND [SolicitudDeTipo].[IdProveedor] >= @pIdProveedor_Start) OR
          (@pIdProveedor_Start IS NULL AND @pIdProveedor_End IS NULL))) OR
       (@pIdProveedor IS NOT NULL AND [SolicitudDeTipo].[IdProveedor] = @pIdProveedor))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [TipoProdEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_TipoProd_New]
(
 @pTipo VARCHAR(50),
 @pCategoria SMALLINT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [TipoProd]
(
    [TipoProd].[Tipo],
    [TipoProd].[Categoria]
)
   VALUES
(
    @pTipo,
    @pCategoria
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_TipoProd_Update]
(
   @pId INT,
   @pTipo VARCHAR(50),
   @pCategoria SMALLINT
)
AS
   SET NOCOUNT ON

   UPDATE
      [TipoProd]
   SET
      [TipoProd].[Tipo] = @pTipo,
      [TipoProd].[Categoria] = @pCategoria
   WHERE
      [TipoProd].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_TipoProd_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [TipoProd]
   WHERE
      [TipoProd].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_TipoProd_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [TipoProd].[Id],
      [TipoProd].[Tipo],
      [TipoProd].[Categoria]
   FROM
      [TipoProd]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_TipoProd_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [TipoProd].[Id],
      [TipoProd].[Tipo],
      [TipoProd].[Categoria]
   FROM
      [TipoProd]
   WHERE
      [TipoProd].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_TipoProd_FindBy]
   @pId INT = NULL,
   @pTipo_ExactMatching INT = NULL,
   @pTipo VARCHAR(50) = NULL,
   @pCategoria SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [TipoProd].[Id],
      [TipoProd].[Tipo],
      [TipoProd].[Categoria]
   FROM
      [TipoProd]
   WHERE
      (@pId IS NULL OR [TipoProd].[Id] = @pId)
       AND
      (@pTipo IS NULL OR [TipoProd].[Tipo] LIKE (CASE @pTipo_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pTipo + (CASE @pTipo_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pCategoria IS NULL OR [TipoProd].[Categoria] = @pCategoria)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_TipoProd_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_TipoProd_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_TipoProd_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pTipo_ExactMatching INT = NULL,
   @pTipo VARCHAR(50) = NULL,
   @pCategoria_Start SMALLINT = NULL,
   @pCategoria_End SMALLINT = NULL,
   @pCategoria SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [TipoProd].[Id],
      [TipoProd].[Tipo],
      [TipoProd].[Categoria]
   FROM
      [TipoProd]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [TipoProd].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [TipoProd].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [TipoProd].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [TipoProd].[Id] = @pId))
 AND
      (@pTipo IS NULL OR [TipoProd].[Tipo] LIKE (CASE @pTipo_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pTipo + (CASE @pTipo_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pCategoria IS NULL AND 
         ((@pCategoria_Start IS NOT NULL AND @pCategoria_End IS NOT NULL AND [TipoProd].[Categoria] BETWEEN @pCategoria_Start AND @pCategoria_End) OR
          (@pCategoria_Start IS NULL AND @pCategoria_End IS NOT NULL AND [TipoProd].[Categoria] <= @pCategoria_End) OR
          (@pCategoria_Start IS NOT NULL AND @pCategoria_End IS NULL AND [TipoProd].[Categoria] >= @pCategoria_Start) OR
          (@pCategoria_Start IS NULL AND @pCategoria_End IS NULL))) OR
       (@pCategoria IS NOT NULL AND [TipoProd].[Categoria] = @pCategoria))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [UsuarioBodaEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_UsuarioBoda_New]
(
 @pIdUsuario INT,
 @pIdBoda INT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [UsuarioBoda]
(
    [UsuarioBoda].[IdUsuario],
    [UsuarioBoda].[IdBoda]
)
   VALUES
(
    @pIdUsuario,
    @pIdBoda
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_UsuarioBoda_Update]
(
   @pId INT,
   @pIdUsuario INT,
   @pIdBoda INT
)
AS
   SET NOCOUNT ON

   UPDATE
      [UsuarioBoda]
   SET
      [UsuarioBoda].[IdUsuario] = @pIdUsuario,
      [UsuarioBoda].[IdBoda] = @pIdBoda
   WHERE
      [UsuarioBoda].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_UsuarioBoda_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [UsuarioBoda]
   WHERE
      [UsuarioBoda].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_UsuarioBoda_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [UsuarioBoda].[Id],
      [UsuarioBoda].[IdUsuario],
      [UsuarioBoda].[IdBoda]
   FROM
      [UsuarioBoda]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_UsuarioBoda_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [UsuarioBoda].[Id],
      [UsuarioBoda].[IdUsuario],
      [UsuarioBoda].[IdBoda]
   FROM
      [UsuarioBoda]
   WHERE
      [UsuarioBoda].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_UsuarioBoda_FindBy]
   @pId INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdBoda INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [UsuarioBoda].[Id],
      [UsuarioBoda].[IdUsuario],
      [UsuarioBoda].[IdBoda]
   FROM
      [UsuarioBoda]
   WHERE
      (@pId IS NULL OR [UsuarioBoda].[Id] = @pId)
       AND
      (@pIdUsuario IS NULL OR [UsuarioBoda].[IdUsuario] = @pIdUsuario)
       AND
      (@pIdBoda IS NULL OR [UsuarioBoda].[IdBoda] = @pIdBoda)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_UsuarioBoda_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_UsuarioBoda_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_UsuarioBoda_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pIdUsuario_Start INT = NULL,
   @pIdUsuario_End INT = NULL,
   @pIdUsuario INT = NULL,
   @pIdBoda_Start INT = NULL,
   @pIdBoda_End INT = NULL,
   @pIdBoda INT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [UsuarioBoda].[Id],
      [UsuarioBoda].[IdUsuario],
      [UsuarioBoda].[IdBoda]
   FROM
      [UsuarioBoda]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [UsuarioBoda].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [UsuarioBoda].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [UsuarioBoda].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [UsuarioBoda].[Id] = @pId))
 AND
      ((@pIdUsuario IS NULL AND 
         ((@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NOT NULL AND [UsuarioBoda].[IdUsuario] BETWEEN @pIdUsuario_Start AND @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NOT NULL AND [UsuarioBoda].[IdUsuario] <= @pIdUsuario_End) OR
          (@pIdUsuario_Start IS NOT NULL AND @pIdUsuario_End IS NULL AND [UsuarioBoda].[IdUsuario] >= @pIdUsuario_Start) OR
          (@pIdUsuario_Start IS NULL AND @pIdUsuario_End IS NULL))) OR
       (@pIdUsuario IS NOT NULL AND [UsuarioBoda].[IdUsuario] = @pIdUsuario))
 AND
      ((@pIdBoda IS NULL AND 
         ((@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NOT NULL AND [UsuarioBoda].[IdBoda] BETWEEN @pIdBoda_Start AND @pIdBoda_End) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NOT NULL AND [UsuarioBoda].[IdBoda] <= @pIdBoda_End) OR
          (@pIdBoda_Start IS NOT NULL AND @pIdBoda_End IS NULL AND [UsuarioBoda].[IdBoda] >= @pIdBoda_Start) OR
          (@pIdBoda_Start IS NULL AND @pIdBoda_End IS NULL))) OR
       (@pIdBoda IS NOT NULL AND [UsuarioBoda].[IdBoda] = @pIdBoda))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************
-- Entity: [UsuarioEntity]
--******************************************************************

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_New]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_New]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Usuario_New]
(
 @pNombre VARCHAR(50),
 @pApellido VARCHAR(50),
 @pNombreUsuario VARCHAR(50),
 @pContrasenia VARCHAR(50),
 @pMail VARCHAR(100),
 @pDNI VARCHAR(15),
 @pDireccion VARCHAR(50),
 @pIdProvincia INT,
 @pIdLocalidad INT,
 @pTipoDNI SMALLINT,
 @pSexo SMALLINT,
 @pId INT OUTPUT
)
AS
   SET NOCOUNT ON

   INSERT INTO
      [Usuario]
(
    [Usuario].[Nombre],
    [Usuario].[Apellido],
    [Usuario].[NombreUsuario],
    [Usuario].[Contrasenia],
    [Usuario].[Mail],
    [Usuario].[DNI],
    [Usuario].[Direccion],
    [Usuario].[IdProvincia],
    [Usuario].[IdLocalidad],
    [Usuario].[TipoDNI],
    [Usuario].[Sexo]
)
   VALUES
(
    @pNombre,
    @pApellido,
    @pNombreUsuario,
    @pContrasenia,
    @pMail,
    @pDNI,
    @pDireccion,
    @pIdProvincia,
    @pIdLocalidad,
    @pTipoDNI,
    @pSexo
)

   SELECT @pId = CAST(SCOPE_IDENTITY() AS INT)

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[f_Usuario_Update]
(
   @pId INT,
   @pNombre VARCHAR(50),
   @pApellido VARCHAR(50),
   @pNombreUsuario VARCHAR(50),
   @pContrasenia VARCHAR(50),
   @pMail VARCHAR(100),
   @pDNI VARCHAR(15),
   @pDireccion VARCHAR(50),
   @pIdProvincia INT,
   @pIdLocalidad INT,
   @pTipoDNI SMALLINT,
   @pSexo SMALLINT
)
AS
   SET NOCOUNT ON

   UPDATE
      [Usuario]
   SET
      [Usuario].[Nombre] = @pNombre,
      [Usuario].[Apellido] = @pApellido,
      [Usuario].[NombreUsuario] = @pNombreUsuario,
      [Usuario].[Contrasenia] = @pContrasenia,
      [Usuario].[Mail] = @pMail,
      [Usuario].[DNI] = @pDNI,
      [Usuario].[Direccion] = @pDireccion,
      [Usuario].[IdProvincia] = @pIdProvincia,
      [Usuario].[IdLocalidad] = @pIdLocalidad,
      [Usuario].[TipoDNI] = @pTipoDNI,
      [Usuario].[Sexo] = @pSexo
   WHERE
      [Usuario].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_Delete]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Usuario_Delete]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   DELETE
      [Usuario]
   WHERE
      [Usuario].[Id] = @pId
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_FindAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_FindAll]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Usuario_FindAll]
AS
   SET NOCOUNT ON

   SELECT
      [Usuario].[Id],
      [Usuario].[Nombre],
      [Usuario].[Apellido],
      [Usuario].[NombreUsuario],
      [Usuario].[Contrasenia],
      [Usuario].[Mail],
      [Usuario].[DNI],
      [Usuario].[Direccion],
      [Usuario].[IdProvincia],
      [Usuario].[IdLocalidad],
      [Usuario].[TipoDNI],
      [Usuario].[Sexo]
   FROM
      [Usuario]

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_FindById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_FindById]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Usuario_FindById]
(
   @pId INT
)
AS
   SET NOCOUNT ON

   SELECT
      [Usuario].[Id],
      [Usuario].[Nombre],
      [Usuario].[Apellido],
      [Usuario].[NombreUsuario],
      [Usuario].[Contrasenia],
      [Usuario].[Mail],
      [Usuario].[DNI],
      [Usuario].[Direccion],
      [Usuario].[IdProvincia],
      [Usuario].[IdLocalidad],
      [Usuario].[TipoDNI],
      [Usuario].[Sexo]
   FROM
      [Usuario]
   WHERE
      [Usuario].[Id] = @pId

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_FindBy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_FindBy]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Usuario_FindBy]
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pApellido_ExactMatching INT = NULL,
   @pApellido VARCHAR(50) = NULL,
   @pNombreUsuario_ExactMatching INT = NULL,
   @pNombreUsuario VARCHAR(50) = NULL,
   @pContrasenia_ExactMatching INT = NULL,
   @pContrasenia VARCHAR(50) = NULL,
   @pMail_ExactMatching INT = NULL,
   @pMail VARCHAR(100) = NULL,
   @pDNI_ExactMatching INT = NULL,
   @pDNI VARCHAR(15) = NULL,
   @pDireccion_ExactMatching INT = NULL,
   @pDireccion VARCHAR(50) = NULL,
   @pIdProvincia INT = NULL,
   @pIdLocalidad INT = NULL,
   @pTipoDNI SMALLINT = NULL,
   @pSexo SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Usuario].[Id],
      [Usuario].[Nombre],
      [Usuario].[Apellido],
      [Usuario].[NombreUsuario],
      [Usuario].[Contrasenia],
      [Usuario].[Mail],
      [Usuario].[DNI],
      [Usuario].[Direccion],
      [Usuario].[IdProvincia],
      [Usuario].[IdLocalidad],
      [Usuario].[TipoDNI],
      [Usuario].[Sexo]
   FROM
      [Usuario]
   WHERE
      (@pId IS NULL OR [Usuario].[Id] = @pId)
       AND
      (@pNombre IS NULL OR [Usuario].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pApellido IS NULL OR [Usuario].[Apellido] LIKE (CASE @pApellido_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pApellido + (CASE @pApellido_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pNombreUsuario IS NULL OR [Usuario].[NombreUsuario] LIKE (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombreUsuario + (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pContrasenia IS NULL OR [Usuario].[Contrasenia] LIKE (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pContrasenia + (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pMail IS NULL OR [Usuario].[Mail] LIKE (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pMail + (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pDNI IS NULL OR [Usuario].[DNI] LIKE (CASE @pDNI_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDNI + (CASE @pDNI_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pDireccion IS NULL OR [Usuario].[Direccion] LIKE (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDireccion + (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END))
       AND
      (@pIdProvincia IS NULL OR [Usuario].[IdProvincia] = @pIdProvincia)
       AND
      (@pIdLocalidad IS NULL OR [Usuario].[IdLocalidad] = @pIdLocalidad)
       AND
      (@pTipoDNI IS NULL OR [Usuario].[TipoDNI] = @pTipoDNI)
       AND
      (@pSexo IS NULL OR [Usuario].[Sexo] = @pSexo)
       
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Usuario_FindByRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[f_Usuario_FindByRange]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[f_Usuario_FindByRange]
   @pId_Start INT = NULL,
   @pId_End INT = NULL,
   @pId INT = NULL,
   @pNombre_ExactMatching INT = NULL,
   @pNombre VARCHAR(50) = NULL,
   @pApellido_ExactMatching INT = NULL,
   @pApellido VARCHAR(50) = NULL,
   @pNombreUsuario_ExactMatching INT = NULL,
   @pNombreUsuario VARCHAR(50) = NULL,
   @pContrasenia_ExactMatching INT = NULL,
   @pContrasenia VARCHAR(50) = NULL,
   @pMail_ExactMatching INT = NULL,
   @pMail VARCHAR(100) = NULL,
   @pDNI_ExactMatching INT = NULL,
   @pDNI VARCHAR(15) = NULL,
   @pDireccion_ExactMatching INT = NULL,
   @pDireccion VARCHAR(50) = NULL,
   @pIdProvincia_Start INT = NULL,
   @pIdProvincia_End INT = NULL,
   @pIdProvincia INT = NULL,
   @pIdLocalidad_Start INT = NULL,
   @pIdLocalidad_End INT = NULL,
   @pIdLocalidad INT = NULL,
   @pTipoDNI_Start SMALLINT = NULL,
   @pTipoDNI_End SMALLINT = NULL,
   @pTipoDNI SMALLINT = NULL,
   @pSexo_Start SMALLINT = NULL,
   @pSexo_End SMALLINT = NULL,
   @pSexo SMALLINT = NULL
AS
   SET NOCOUNT ON

   SELECT
      [Usuario].[Id],
      [Usuario].[Nombre],
      [Usuario].[Apellido],
      [Usuario].[NombreUsuario],
      [Usuario].[Contrasenia],
      [Usuario].[Mail],
      [Usuario].[DNI],
      [Usuario].[Direccion],
      [Usuario].[IdProvincia],
      [Usuario].[IdLocalidad],
      [Usuario].[TipoDNI],
      [Usuario].[Sexo]
   FROM
      [Usuario]
   WHERE
      ((@pId IS NULL AND 
         ((@pId_Start IS NOT NULL AND @pId_End IS NOT NULL AND [Usuario].[Id] BETWEEN @pId_Start AND @pId_End) OR
          (@pId_Start IS NULL AND @pId_End IS NOT NULL AND [Usuario].[Id] <= @pId_End) OR
          (@pId_Start IS NOT NULL AND @pId_End IS NULL AND [Usuario].[Id] >= @pId_Start) OR
          (@pId_Start IS NULL AND @pId_End IS NULL))) OR
       (@pId IS NOT NULL AND [Usuario].[Id] = @pId))
 AND
      (@pNombre IS NULL OR [Usuario].[Nombre] LIKE (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombre + (CASE @pNombre_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pApellido IS NULL OR [Usuario].[Apellido] LIKE (CASE @pApellido_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pApellido + (CASE @pApellido_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pNombreUsuario IS NULL OR [Usuario].[NombreUsuario] LIKE (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pNombreUsuario + (CASE @pNombreUsuario_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pContrasenia IS NULL OR [Usuario].[Contrasenia] LIKE (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pContrasenia + (CASE @pContrasenia_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pMail IS NULL OR [Usuario].[Mail] LIKE (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pMail + (CASE @pMail_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pDNI IS NULL OR [Usuario].[DNI] LIKE (CASE @pDNI_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDNI + (CASE @pDNI_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      (@pDireccion IS NULL OR [Usuario].[Direccion] LIKE (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END) + @pDireccion + (CASE @pDireccion_ExactMatching WHEN 1 THEN '' ELSE '%' END)) AND
      ((@pIdProvincia IS NULL AND 
         ((@pIdProvincia_Start IS NOT NULL AND @pIdProvincia_End IS NOT NULL AND [Usuario].[IdProvincia] BETWEEN @pIdProvincia_Start AND @pIdProvincia_End) OR
          (@pIdProvincia_Start IS NULL AND @pIdProvincia_End IS NOT NULL AND [Usuario].[IdProvincia] <= @pIdProvincia_End) OR
          (@pIdProvincia_Start IS NOT NULL AND @pIdProvincia_End IS NULL AND [Usuario].[IdProvincia] >= @pIdProvincia_Start) OR
          (@pIdProvincia_Start IS NULL AND @pIdProvincia_End IS NULL))) OR
       (@pIdProvincia IS NOT NULL AND [Usuario].[IdProvincia] = @pIdProvincia))
 AND
      ((@pIdLocalidad IS NULL AND 
         ((@pIdLocalidad_Start IS NOT NULL AND @pIdLocalidad_End IS NOT NULL AND [Usuario].[IdLocalidad] BETWEEN @pIdLocalidad_Start AND @pIdLocalidad_End) OR
          (@pIdLocalidad_Start IS NULL AND @pIdLocalidad_End IS NOT NULL AND [Usuario].[IdLocalidad] <= @pIdLocalidad_End) OR
          (@pIdLocalidad_Start IS NOT NULL AND @pIdLocalidad_End IS NULL AND [Usuario].[IdLocalidad] >= @pIdLocalidad_Start) OR
          (@pIdLocalidad_Start IS NULL AND @pIdLocalidad_End IS NULL))) OR
       (@pIdLocalidad IS NOT NULL AND [Usuario].[IdLocalidad] = @pIdLocalidad))
 AND
      ((@pTipoDNI IS NULL AND 
         ((@pTipoDNI_Start IS NOT NULL AND @pTipoDNI_End IS NOT NULL AND [Usuario].[TipoDNI] BETWEEN @pTipoDNI_Start AND @pTipoDNI_End) OR
          (@pTipoDNI_Start IS NULL AND @pTipoDNI_End IS NOT NULL AND [Usuario].[TipoDNI] <= @pTipoDNI_End) OR
          (@pTipoDNI_Start IS NOT NULL AND @pTipoDNI_End IS NULL AND [Usuario].[TipoDNI] >= @pTipoDNI_Start) OR
          (@pTipoDNI_Start IS NULL AND @pTipoDNI_End IS NULL))) OR
       (@pTipoDNI IS NOT NULL AND [Usuario].[TipoDNI] = @pTipoDNI))
 AND
      ((@pSexo IS NULL AND 
         ((@pSexo_Start IS NOT NULL AND @pSexo_End IS NOT NULL AND [Usuario].[Sexo] BETWEEN @pSexo_Start AND @pSexo_End) OR
          (@pSexo_Start IS NULL AND @pSexo_End IS NOT NULL AND [Usuario].[Sexo] <= @pSexo_End) OR
          (@pSexo_Start IS NOT NULL AND @pSexo_End IS NULL AND [Usuario].[Sexo] >= @pSexo_Start) OR
          (@pSexo_Start IS NULL AND @pSexo_End IS NULL))) OR
       (@pSexo IS NOT NULL AND [Usuario].[Sexo] = @pSexo))
 
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

